package io.renren.modules.bs.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.bs.entity.BsExtractRecordDetailEntity;
import io.renren.modules.bs.service.BsExtractRecordDetailService;
import io.renren.modules.bs.vo.ExtractRecordDetailVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;



/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2019-08-15 23:03:14
 */
@RestController
@RequestMapping("bs/extractRecordDetail")
public class BsExtractRecordDetailController {
    @Autowired
    private BsExtractRecordDetailService bsExtractRecordDetailService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = bsExtractRecordDetailService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 根据抽取获得列表
     */
    @RequestMapping("/listByRecordId")

    public R listByRecordId(Long recordId){


        try {
            List<ExtractRecordDetailVo> extractRecordDetailVoList = bsExtractRecordDetailService.listByRecordId(recordId);
            return R.ok().put("data", extractRecordDetailVoList);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error(e.getMessage());
        }
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{extractRecordDetail}")

    public R info(@PathVariable("extractRecordDetail") Long extractRecordDetail){
		BsExtractRecordDetailEntity bsExtractRecordDetail = bsExtractRecordDetailService.getById(extractRecordDetail);

        return R.ok().put("bsExtractRecordDetail", bsExtractRecordDetail);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody BsExtractRecordDetailEntity bsExtractRecordDetail){
		bsExtractRecordDetailService.save(bsExtractRecordDetail);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")

    public R update(@RequestBody BsExtractRecordDetailEntity bsExtractRecordDetail){
		bsExtractRecordDetailService.updateById(bsExtractRecordDetail);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")

    public R delete(@RequestBody Long[] extractRecordDetails){
		bsExtractRecordDetailService.removeByIds(Arrays.asList(extractRecordDetails));

        return R.ok();
    }

}
